package com.atguigu.spzx.user.controller;

import com.atguigu.spzx.model.entity.user.UserAddress;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.user.service.UserAddressService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Tag(name = "会员地址管理模块")
@RequestMapping("/api/user/userAddress")
public class UserAddressController {

    @Resource
    UserAddressService userAddressService;

    @Operation(summary = "修改用户地址")
    @PutMapping("/auth/updateById")
    public Result updateById(@RequestBody UserAddress userAddress){
        userAddressService.updateById(userAddress);
        return Result.ok();
    }
    @Operation(summary = "新增地址")
    @PostMapping("/auth/save")
    public Result save(@RequestBody UserAddress userAddress){
        userAddressService.save(userAddress);
        return Result.ok();
    }
    @Operation(summary = "根据地址id获取地址详情")
    @GetMapping("/getUserAddress/{id}")
    public Result getUserAddress(@PathVariable("id")Long id){
        UserAddress userAddress = userAddressService.getUserAddress(id);
        return Result.ok().data(userAddress);
    }

    @Operation(summary = "获取地址列表")
    @GetMapping("/auth/findUserAddressList")
    public Result findUserAddressList(){
        List<UserAddress> userAddressList = userAddressService.findUserAddressList();
        return Result.ok().data(userAddressList);
    }
    @Operation(summary = "删除指定地址")
    @DeleteMapping("/auth/removeById/{id}")
    public Result removeById(@PathVariable("id")Long id){
        userAddressService.deleteById(id);
        return Result.ok();
    }

}
